#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int n = nums.size();
        int cur = 0;
        int sum = 0, res = INT_MIN;
        while (cur < n)
        {
            while (cur < n && sum >= 0)
            {
                sum += nums[cur++];
                res = max(res, sum);
            }
            sum = 0;
        }
        return res;
    }
};